package Model.RedisUtils;

import Dao.RedisDao;
import Model.Obj.User;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import java.util.Set;


public class Redis {
    private static JedisPool jedisPool;
    private static Integer max = 20;

    static {init();};

    private static void init(){
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(max);
        jedisPool = new JedisPool(config,"localhost",6379,1000*2);
    }

    public static Jedis getJedis(){
        if (jedisPool != null){
            Jedis jedis = jedisPool.getResource();
            return jedis;
        } else {
            return null;
        }
    }

    public static void setJedis(){
        Jedis jedis = Redis.getJedis();
        List<User> list = RedisDao.setLoginRedis();
        for (User user : list){
            jedis.set(user.getUSERNAME(),user.getPASSWORD());
        }
    }
}
